import json
import collections
import os, re, csv

#f = open('E:\\w\\index.verb', 'r')
#fword = open("e:\\w\\verb_list(wordnet3.1).csv", 'w' ,encoding='utf8')
#for line in f.readlines()[29:]:
#    ll = re.split("[ \t]", line)
#    if re.search("^[a-z]+$", ll[0]):
#        fword.write(ll[0]+"\n");
#
#f.close()
#fword.close()
#
#f = open('E:\\w\\index.noun', 'r')
#fword = open("e:\\w\\noun_list(wordnet3.1).csv", 'w' ,encoding='utf8')
#for line in f.readlines()[29:]:
#    ll = re.split("[ \t]", line)
#    if re.search("^[a-z]+$", ll[0]):
#        fword.write(ll[0]+"\n");
#
#f.close()
#fword.close()
if False:
    f = open('E:\\w\\verb.exc', 'r')
    fword = open("e:\\w\\forms-verb-irregular(wordnet3.1).csv", 'w' ,encoding='utf8')

    words=dict()

    for line in f.readlines():
        ll = re.split("[ \t]", line)
        if re.search("[_'-]", ll[0]) or re.search("[_'-]", ll[1]):
            continue
        w = ll[1].strip()
        form = ll[0].strip()

        if words.get(w) is None:
            words[w] = dict()

        if re.search("s$", form):
            tag = "single"
            if words[w].get(tag) is None:
                words[w][tag] = []
            words[w][tag].append(form)
            pass

        elif re.search("ing$", form):
            tag = "ing"
            if words[w].get(tag) is None:
                words[w][tag] = []
            words[w][tag].append(form)
            pass
        else:
            tag = "ed"
            if words[w].get(tag) is None:
                words[w][tag] = []
            words[w][tag].append(form)
            pass

    for word, info in words.items():
        present_participle = info.get("ing") or []
        past_participle = info.get("ed") or []
        past_tense = info.get("ed") or []
        third_person_singular = info.get("single") or []

        fword.write(word+"|"+"{}|{}|{}|{}\n".format(",".join(p for p in present_participle),",".join(p for p in past_participle),",".join(p for p in past_tense),",".join(p for p in third_person_singular) ))

    f.close()
    fword.close()

if True:
    f = open('E:\\w\\noun.exc', 'r')
    fword = open("e:\\w\\forms-noun-irregular(wordnet3.1).csv", 'w' ,encoding='utf8')

    words=dict()

    for line in f.readlines():
        ll = re.split("[ \t]", line)
        if re.search("[_'-]", ll[0]) or re.search("[_'-]", ll[1]):
            continue
        w = ll[1].strip()
        form = ll[0].strip()

        if words.get(w) is None:
            words[w] = dict()

        if True:
            tag = "pl"
            if words[w].get(tag) is None:
                words[w][tag] = []
            words[w][tag].append(form)
            pass

    for word, info in words.items():
        pl = info.get("pl") or []

        fword.write(word+"|"+"{}\n".format(",".join(p for p in pl) ))

    f.close()
    fword.close()
